package middleware

import (
	"time"
	"tyjt-ferry/internal/config"
	"tyjt-ferry/internal/service"
	"tyjt-ferry/pkg/jwtauth"
)

func AuthInit() (*jwtauth.GinJWTMiddleware, error) {
	return jwtauth.New(&jwtauth.GinJWTMiddleware{
		Realm:           "test zone",
		Key:             []byte(config.JwtConfig.Secret),
		Timeout:         time.Hour,
		MaxRefresh:      time.Hour,
		PayloadFunc:     service.PayloadFunc,     //
		IdentityHandler: service.IdentityHandler, //
		Authenticator:   service.Authenticator,   // 登录
		Authorizator:    service.Authorizator,    // 授权
		Unauthorized:    service.Unauthorized,    // 未授权
		TokenLookup:     "header: Authorization, query: token, cookie: jwt",
		TokenHeadName:   "Bearer",
		TimeFunc:        time.Now,
	})
}
